package com.fairytask.ui.main
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.MailFrameUI;
	import com.fairytask.ui.MiniMapUI;
	import com.fairytask.ui.RankUI;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	/**
	 * 主界面小地图信息
	 * @author xujh
	 * 
	 */
	public class MainMapUI extends FrameUI
	{
		private static var _self		:MainMapUI;
		
		public var business_mc	:Clip; 		//背景图
		public var rankBtn		:Button;	//排行榜
		public var MBtn 		:Button;    //信件
		public var worldMapBtn	:Button;    //小地图
		public var sceneLab	:Label;		//场景名称
		
		private var _userPos	:Point;
		private var _userMap	:String;
		private var _mapName	:String;
		
		public static function getInstance():MainMapUI
		{
			if(_self == null)
			{
				_self	=	new MainMapUI();				
			}
			return _self;
		}
		
		public function MainMapUI(popUI:Boolean=false)
		{
			super(popUI);
			this.userMap = StaticIni.getSwfLangStr(String(model.scene.Model));
			initEvent();
		}
		
		/**
		 * 初始化事件 
		 */
		private function initEvent():void
		{
			//小地图
			worldMapBtn.addEventListener(MouseEvent.CLICK,onWorldMapBtn);
			//信件
			MBtn.addEventListener(MouseEvent.CLICK,onMail);
			//排行榜
			rankBtn.addEventListener(MouseEvent.CLICK,onRank);
		}
		
		/**
		 * 世界按钮点击 
		 * @param evt
		 * 
		 */		
		private function onWorldMapBtn(evt:MouseEvent):void
		{
			MiniMapUI.getInstance().show();
		}
		/**
		 * 信件按钮点击 
		 * @param evt
		 * 
		 */
		private function onMail(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTMMSG_CLIENT_MAILBOX,1);
			MailFrameUI.getInstance().show();
		}
		private function onRank(evt:MouseEvent):void
		{
			RankUI.getInstance().show();
		}
		
		public function get userMap():String
		{
			return _userMap;
		}
		
		public function set modelID(val:String):void
		{
			_mapName=val;
		}
		
		public function set userMap(value:String):void
		{
			sceneLab.htmlStrByBorder	= 	value;
			sceneLab.x=40 + (120 - sceneLab.width)/2;
		}
		
		public function set canMiniMap(val:Boolean):void
		{
			worldMapBtn.enabled = val;
		}
		
		/**
		 * 重写显示 
		 * @param space
		 * @param onshow
		 * @param argc
		 * 
		 */
		override public function show(space:String=BACKLAYER, onshow:Function=null):void
		{
			//默认不可用
			worldMapBtn.enabled = false;
			super.show(space,onshow);
		}
		
		/**
		 * 场景变化改变位置 
		 * 
		 */
		override protected function stageReSize(evt:Event=null):void
		{
			this.x	=	initX + GameStage.mainLayer.x;
			this.y = 	initY - GameStage.mainLayer.y;
		}
	}
}